from django.db import models




class TourUser(models.Model):
    uname = models.CharField('昵称', max_length=20, null=False)
    uphoto = models.CharField(verbose_name="头像",max_length=100,null=True,blank=True)
    uphone = models.CharField('电话', max_length=11, null=False, unique=True)
    upwd = models.CharField('密码', max_length=15, null=False)
    sex_choice = (
        (0, '女性'),
        (1, '男性'),
        (2, '不显示'),
    )
    usex = models.IntegerField('性别', choices=sex_choice, default=2)  # choices关键字固定的
    uage = models.IntegerField('年龄', default='18')
    def __str__(self):
        return '%s-%s-%s-%s'%(self.uname,self.uphone,self.usex,self.uage)

    class Meta:
        db_table = '用户管理'
        verbose_name = '用户管理'
        verbose_name_plural = verbose_name


class ReadTour(models.Model):
    from ScenicSpot.models import TourName
    uphone = models.CharField('电话', max_length=11, null=False)
    tid = models.ForeignKey(TourName, on_delete=models.CASCADE, verbose_name='已阅读文章') # 标签
    created = models.DateTimeField(verbose_name="第一次阅读时间", auto_now_add=True)  # 设置模型对象第一次创建时的系统时间
    updated = models.DateTimeField(verbose_name="最新阅读时间", auto_now=True)  # 每次修改model，都会自动更新

    def __str__(self):
        return '%s-%s-%s-%s'%(self.uphone,self.tid,self.created,self.uphone)

    class Meta:
        db_table = '阅读管理'
        verbose_name = '阅读管理'
        verbose_name_plural = verbose_name


class LikeTour(models.Model):
    from ScenicSpot.models import TourName
    uphone = models.CharField('电话', max_length=11, null=False)
    tid = models.ForeignKey(TourName, on_delete=models.CASCADE, verbose_name='点赞文章') # 标签


    def __str__(self):
        return '%s-%s'%(self.uphone,self.tid,)

    class Meta:
        db_table = '点赞管理'
        verbose_name = '点赞管理'
        verbose_name_plural = verbose_name


class com(models.Model):
    text = models.TextField(max_length=500,verbose_name="评论内容")
    # 评论内容
    datetime = models.DateTimeField('评论日期', auto_now= True) # 评论日期
    from ScenicSpot.models import TourName
    about = models.ForeignKey(TourName,on_delete=models.CASCADE,verbose_name="所属博文") # 所属博文
    user = models.ForeignKey(TourUser,on_delete=models.CASCADE,verbose_name="所属用户")
    def __str__(self):
        return '%s-%s-%s'%( self.text, self.datetime, self.about,)

    class Meta:
        db_table = '评论管理'
        verbose_name = '评论管理'
        verbose_name_plural = verbose_name